package com.cyw.common.config.jackson.serializer;

import com.cyw.common.utils.DecimalUtils;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 金钱 序列化器
 *
 * @Author:cyw
 * @CreateTime: 2021年3月31日15:04:50
 **/
public class MoneySerializer extends StdSerializer<BigDecimal> {

    private static final long serialVersionUID = -5224774752589097648L;

    public MoneySerializer() {
        this(null);
    }

    public MoneySerializer(Class<BigDecimal> t) {
        super(t);
    }

    @Override
    public void serialize(BigDecimal value, JsonGenerator gen, SerializerProvider provider) throws IOException {
        gen.writeNumber(value.setScale(DecimalUtils.DECIMAL_BIT_TWO, RoundingMode.HALF_UP));
    }
}



    
    
    
    
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    